package com.lt.flashcard.view;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;

import com.lt.flashcard.Utility;
import com.lt.flashcard.model.entity.Content;
import com.lt.flashcard.model.entity.ContentCategory;
import com.lt.flashcard.model.service.ContentService;
import com.lt.flashcard.model.service.Repository;

public class AboutFlashcardVm {
	
	/**
	 * Current displayed content
	 */
	private Content content;
	private List<ContentCategory> categories;
	
	@Init
	public void init() {
		ContentService srv = Repository.getInstance().getContentService();
		ContentCategory cat = srv.getCategory(Utility.getConfiguration("com.lt.flashcard.aboutflashcard_category", ""));
		categories = cat.getChild();
	}
	
	@NotifyChange("content")
	@Command
	public void view(@BindingParam("id") String id) {
		if(StringUtils.isNotBlank(id)) {
			ContentService srv = Repository.getInstance().getContentService();
			content = srv.getContent(id);
		}
	}

	public Content getContent() {
		return content;
	}

	public void setContent(Content content) {
		this.content = content;
	}

	public List<ContentCategory> getCategories() {
		return categories;
	}

	public void setCategories(List<ContentCategory> categories) {
		this.categories = categories;
	}
}
